﻿/////////////////////////////////////////////////////////////////
//File: BlogInfo.cs
//Description: 
//Copyright© 2011 Moliu
//History:
//  2011-3-14 0:38:21    CodeSmith5.0.1    Original Version
/////////////////////////////////////////////////////////////////
using System;
using System.Collections;
using MAF.Common;
using System.Security.Principal;
using My.Blog.Domain.Entities;
using My.Blog.Domain.Interfaces;
using My.Blog.Business.Persistence;


namespace My.Blog.Business.Security
{

    /// <summary>
    /// IPrincipal
    /// </summary>
    public class BlogPrincipal : IPrincipal
    {
        #region 构造函数

        public BlogPrincipal(BlogIdentity id)
        {
            _Identity = id;  
        }

        #endregion

        #region IPrincipal 成员

        public IIdentity Identity
        {
            get { return _Identity; }
        }

        // 系统有两种角色
        //  1. 系统角色--管理员,sys:
        //  2. 博客角色--本博主,blog:
        // 此方法只能判断sys角色,blog角色只能在业务服务里判断
        // role格式: sys:roleId;blog:roleId
        public bool IsInRole(string role)
        {
            // 此是测试代码
            return "Admin".ToLower() == role;
            
            //// 取出两个角色Id
            //string[] allRoles = role.Split(';');
            //string sysRole = "";
            //string blogRole = "";
            //for( int i=0,len=allRoles.Length;i<len;i++ )
            //{
            //    if( allRoles[i].Trim().StartsWith("blog") )
            //        blogRole = allRoles[i].Split(':')[1].Trim();
            //    else if( allRoles[i].Trim().StartsWith("sys") )
            //        sysRole = allRoles[i].Split(':')[1].Trim();
            //}
        }
        #endregion

        #region Protected Member
        protected BlogIdentity _Identity = null;
        #endregion
    }
}